package com.helen.wechat.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import com.helen.wechat.entity.ContactEntity;

@Component
public class UserDaoImpl implements UserDao {
	@Autowired
	private MongoTemplate mongoTemplate;

	@Override
	public void saveUser(ContactEntity user) {
		mongoTemplate.save(user);
	}

	@Override
	public ContactEntity findUserByUserName(String userName) {
		Query query = new Query(Criteria.where("userName").is(userName));
		ContactEntity user = mongoTemplate.findOne(query, ContactEntity.class);
		return user;
	}

}
